package com.sense.kukoo.biz_me.model

import com.sense.kukoo.common.mvvm.model.BaseMvvmModel
import com.sense.kukoo.common.repo.bean.ResultBean
import com.sense.kukoo.common.repo.http.KukooHttpApi
import com.sense.kukoo.common.repo.http.KukooHttpManager
import com.sense.kukoo.common.repo.http.bean.LoginResultBean
import com.sense.kukoo.common.repo.http.bean.UserInfoBean
import okhttp3.RequestBody

class VerifyCodeModel: BaseMvvmModel() {

    private val TAG: String = javaClass.simpleName
    override fun onModelCleared() {}

    suspend fun sendVerifyCode(
        areaCode: String,
        mobile: String,
    ): ResultBean<Boolean> {
        val hashMap = HashMap<String, Any>()
        hashMap.put("areaCode", areaCode)
        hashMap.put("mobile", mobile)
        val mRequestBody: RequestBody = KukooHttpManager.createRequestBody(hashMap)

        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .sendVerifyCode(mRequestBody)
    }

    suspend fun login(
        account: String,
        areaCode: String? = null,
        password: String? = null,
        verifyCode: String? = null
    ): ResultBean<LoginResultBean> {
        val hashMap = HashMap<String, Any>()
        hashMap.put("account", account)
        areaCode?.let {
            hashMap.put("areaCode", it)
        }
        password?.let {
            hashMap.put("password", it)
        }
        verifyCode?.let {
            hashMap.put("verifyCode", it)
        }
        val mRequestBody: RequestBody = KukooHttpManager.createRequestBody(hashMap)

        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .login(mRequestBody)
    }

    suspend fun getUserInfo(): ResultBean<UserInfoBean> {
        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .getUserInfo("0")
    }
}